#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>

#include<sys/wait.h>
#include<sys/types.h>
int main()
{
    pid_t id = fork();

    if(id == 0)
    {
        execlp("ls","ls","-l","-a",NULL);
        //child
        printf("i am a child,pid:%d,ppid:%d\n",getpid(),getppid());
        sleep(10);
        exit(0);
    }
    printf("i am a father,pid:%d,ppid:%d\n",getpid(),getppid());
    int status = 0;
    pid_t rid = waitpid(id,&status,0);
    if(rid > 0)
    {
        if(WIFEXITED(status))
        {
            //正常结束
            printf("%d\n",WEXITSTATUS(status));
        }
        else 
        {
            printf("进程异常退出\n");
        }
    }
}
